package com.leet.tree;

import java.util.ArrayList;
import java.util.List;

public class GetMinimumDifference {
    private int ans = Integer.MAX_VALUE;
    List<Integer> list = new ArrayList<>();
    public int getMinimumDifference(TreeNode root) {
        helper(root);
        for (int i = 0; i < list.size()-1; i++) {
            if(Math.abs(list.get(i+1) - list.get(i)) < ans){
                ans = Math.abs(list.get(i+1) - list.get(i));
        }
        }
        return ans;
    }
    public void helper(TreeNode root){
        if(root == null) return;
        list.add(root.val);
        helper(root.left);
        helper(root.right);
    }
}
